home *** CD-ROM | disk | FTP | other *** search
- #include <Quickdraw.h>
- #include <Windows.h>
- #include <Memory.h>
-
- #define LOWORD(x) (x & 0x0000FFFF)
- #define HIWORD(x) ((x>>16) & 0x0000FFFF)
-
- /*
- prototypes
- */
-
- pascal long main(short varCode,WindowPeek theWindow,short message,long param);
- long DoDrawWindow(short varCode,WindowPeek theWindow,long param);
- long DoHit(short varCode,WindowPeek theWindow,long param);
- long DoCalcRgns(short varCode,WindowPeek theWindow,long param);
- long DoNew(short varCode,WindowPeek theWindow,long param);
- long DoDispose(short varCode,WindowPeek theWindow,long param);
- long DoGrow(short varCode,WindowPeek theWindow,long param);
- long DoDrawGIcon(short varCode,WindowPeek theWindow,long param);
- void GetTitleRect(WindowPeek theWindow,Rect *r);
- void GetGoAwayRect(WindowPeek theWindow,Rect *r);
- void GetChangerRect(WindowPeek theWindow,Rect *r);
- void DrawTitleBar(WindowPeek theWindow);
- void DrawWindowTitle(WindowPeek theWindow);
- void DrawGoAwayBox(WindowPeek theWindow);
- void HiliteGoAwayBox(WindowPeek theWindow);
-
- pascal long main(short varCode,WindowPeek theWindow,short message,long param)
- {
- long result;
-
- switch(message)
- {
- case wDraw:
- result = DoDrawWindow(varCode,theWindow,param);
- break;
- case wHit:
- result = DoHit(varCode,theWindow,param);
- break;
- case wCalcRgns:
- result = DoCalcRgns(varCode,theWindow,param);
- break;
- case wNew:
- result = DoNew(varCode,theWindow,param);
- break;
- case wDispose:
- result = DoDispose(varCode,theWindow,param);
- break;
- case wGrow:
- result = DoGrow(varCode,theWindow,param);
- break;
- case wDrawGIcon:
- result = DoDrawGIcon(varCode,theWindow,param);
- break;
- default:
- result = 0;
- break;
- }
- return result;
- }
-
- long DoDrawWindow(short varCode,WindowPeek theWindow,long param)
- {
- short code;
-
- code = LOWORD(param);
-
- if(theWindow->visible)
- {
- switch(code)
- {
- case 0:
- // draw entire window frame
- DrawTitleBar(theWindow);
- if(theWindow->hilited)
- DrawGoAwayBox(theWindow);
- FrameRgn(theWindow->strucRgn);
- break;
- case wInGoAway:
- HiliteGoAwayBox(theWindow);
- break;
- default:
- break;
- }
- }
- return 0;
- }
-
- long DoHit(short varCode,WindowPeek theWindow,long param)
- {
- Point p;
- Rect r;
- long result = wNoHit;
- Rect titleRect;
-
- p.h = LOWORD(param);
- p.v = HIWORD(param);
-
- if(PtInRgn(p,theWindow->contRgn))
- {
- result = wInContent;
- }
- else if(PtInRgn(p,theWindow->strucRgn))
- {
- GetTitleRect(theWindow,&titleRect);
- if(PtInRect(p,&titleRect))
- result = wInDrag;
- if(theWindow->hilited)
- {
- GetGoAwayRect(theWindow,&r);
- if(PtInRect(p,&r))
- result = wInGoAway;
- }
- }
- return result;
- }
-
- long DoCalcRgns(short varCode,WindowPeek theWindow,long param)
- {
- Rect tRect;
- Rect pRect;
- Rect bRect;
-
- pRect = theWindow->port.portRect;
- bRect = theWindow->port.portBits.bounds;
- OffsetRect(&pRect,-bRect.left,-bRect.top);
-
- OpenRgn();
- FrameRect(&pRect);
- CloseRgn(theWindow->contRgn);
-
- GetTitleRect(theWindow,&tRect);
- InsetRect(&pRect,-1,-1);
- pRect.top -= tRect.bottom - tRect.top - 1;
- OpenRgn();
- FrameRect(&pRect);
- CloseRgn(theWindow->strucRgn);
-
- return 0;
- }
-
- long DoNew(short varCode,WindowPeek theWindow,long param)
- {
- theWindow->spareFlag = true;
- theWindow->goAwayFlag = false;
- return 0;
- }
-
- long DoDispose(short varCode,WindowPeek theWindow,long param)
- {
- return 0;
- }
-
- long DoGrow(short varCode,WindowPeek theWindow,long param)
- {
- return 0;
- }
-
- long DoDrawGIcon(short varCode,WindowPeek theWindow,long param)
- {
- return 0;
- }
-
- void GetTitleRect(WindowPeek theWindow,Rect *r)
- {
- FontInfo fInfo;
-
- GetFontInfo(&fInfo);
- *r = (**theWindow->strucRgn).rgnBBox;
- r->bottom = r->top+fInfo.ascent+fInfo.descent+4;
- }
-
- void GetGoAwayRect(WindowPeek theWindow,Rect *r)
- {
- GetTitleRect(theWindow,r);
- r->top += 4;
- r->left += 8;
- r->bottom = r->top + 11;
- r->right = r->left + 11;
- }
-
- void DrawTitleBar(WindowPeek theWindow)
- {
- Rect r;
- Pattern p;
-
- p.pat[0]=0x88;
- p.pat[1]=0x44;
- p.pat[2]=0x22;
- p.pat[3]=0x11;
- p.pat[4]=0x88;
- p.pat[5]=0x44;
- p.pat[6]=0x22;
- p.pat[7]=0x11;
-
- PenNormal();
- GetTitleRect(theWindow,&r);
- FrameRect(&r);
- InsetRect(&r,1,1);
- EraseRect(&r);
- if(theWindow->hilited)
- {
- FillRect(&r,(ConstPatternParam)&p);
- }
- }
-
- void DrawWindowTitle(WindowPeek theWindow)
- {
- FontInfo fInfo;
- short tLeftMargin;
- Rect r;
-
- GetFontInfo(&fInfo);
- GetTitleRect(theWindow,&r);
- tLeftMargin = (r.right - r.left - theWindow->titleWidth)/2;
- MoveTo(r.left + tLeftMargin,r.top + fInfo.ascent + 2);
- HLock((Handle)theWindow->titleHandle);
- DrawString(*theWindow->titleHandle);
- HUnlock((Handle)theWindow->titleHandle);
- }
-
- void DrawGoAwayBox(WindowPeek theWindow)
- {
- Rect r;
-
- GetGoAwayRect(theWindow,&r);
- FrameRect(&r);
- InsetRect(&r,1,1);
- EraseRect(&r);
- }
-
- void HiliteGoAwayBox(WindowPeek theWindow)
- {
- Rect r;
-
- GetGoAwayRect(theWindow,&r);
- FrameRect(&r);
- InsetRect(&r,1,1);
- InvertRect(&r);
- }
-